package produc

import (
	"gitee.com/enjoy_5/order-rpc/internal/model/product"
	proto "gitee.com/enjoy_5/order-rpc/proto/order"
)

func GetOrderGoodsList(orderid int64) ([]*proto.OrderGoodsInfo, error) {
	g := new(product.OrderGoods)
	list, err := g.OrderGoodsList(orderid)
	if err != nil {
		return nil, err
	}
	// 预先分配 ordergoods 切片的容量
	ordergoods := make([]*proto.OrderGoodsInfo, 0, len(list))
	for _, v := range list {
		ordergoods = append(ordergoods, &proto.OrderGoodsInfo{
			OrderId:  v.OrderId,
			GoodsId:  v.GoodId,
			SkuId:    v.SkuID,
			Price:    v.Price,
			Quantity: v.Quantity,
		})
	}
	return ordergoods, nil
}
